home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_Misc.c
-
- Contains: Misc utility routines.
-
- Written by: David H Nelson
-
- Copyright © 1988-1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- <1> 1988 DHN Created.
- */
-
- #include <Quickdraw.h>
- #include <GestaltEqu.h>
- #include <Drag.h>
- #include <OSUtils.h>
-
- #include "CAS_CTools.h"
- #include "CAS_Dialog.h"
- #include "CAS_StringTools.h"
- #include "CAS_Misc.h"
-
-
- //---------------------------------------------------------------------------
- static short iCurCursorID = 0;
- static short iWhichCursor = 0;
- static long lCursorTicks = 0;
- static BitMap bmSrc = { nil, 0x0002, { 0, 0, 16, 16 } };
- static Rect rTemp = { 0, 0, 16, 16 };
-
-
- //----------------------------------------------------------------------
- // local prototypes
-
- #if defined(__cplusplus)
- extern "C"
- {
- #endif
-
- static void DeviceLoopPlus(
- Boolean usingSystem7,
- Boolean using32BitQD,
- RgnHandle drawingRgn,
- DeviceLoopDrawingProcPtr drawingProc,
- long userData,
- DeviceLoopFlags flags );
-
- #if defined(__cplusplus)
- }
- #endif
-
-
- //---------------------------------------------------------------------------
- // return the number of copies the user requested from prJob.iCopies.
-
- short howManyCopies(
- THPrint hPrint )
- {
- if (hPrint == nil)
- return 0;
-
- return
- (((**hPrint).prJob.bJDocLoop == bDraftLoop)
- ? (**hPrint).prJob.iCopies : 1 );
- }
-
- //---------------------------------------------------------------------------
- // checkPrintHandle - make sure the print handle is allocated and initialized. Return false if
- // we failed, true if we succeed.
- Boolean checkPrintHandle(
- THPrint *hPrint )
- {
- OSErr theErr;
-
- theErr = PrError();
- if (theErr == noErr)
- {
- if (*hPrint != nil)
- PrValidate( *hPrint );
- else
- {
- *hPrint = (TPrint**)NewHandleClear( (long)sizeof(TPrint) );
- if (*hPrint == nil)
- theErr = memFullErr;
- else
- PrintDefault( *hPrint );
- }
- }
-
- if (theErr == noErr)
- theErr = PrError();
-
- return (theErr == noErr);
- }
-
-
- //---------------------------------------------------------------------------
- // Return the number of Toolbox traps that are available on this machine. Return
- // 0x0200 if InitGraf is the same address as trap AA6E, 0x0400 otherwise.
-
- short NumToolboxTraps( void )
- {
- if (NGetTrapAddress( _InitGraf, ToolTrap ) == NGetTrapAddress( 0xAA6E, ToolTrap ))
- return 0x0200;
- else
- return 0x0400;
- }
-
- //---------------------------------------------------------------------------
- // Return the type of the given trap. The TrapType is used by NGetTrapAddress.
-
- TrapType GetTrapType(
- short theTrap )
- {
- #define TrapMask 0x0800
-
- if ((theTrap & TrapMask) != 0)
- return ToolTrap;
- else
- return OSTrap;
- }
-
- //---------------------------------------------------------------------------
- // Check to see if the given trap is available on this machine. Return true if
- // it is, false if not.
-
- Boolean TrapAvailable(
- short theTrap )
- {
- TrapType tType;
-
- tType = GetTrapType( theTrap );
- if (tType == ToolTrap)
- theTrap = theTrap & 0x07FF;
- if (theTrap >= NumToolboxTraps())
- theTrap = _Unimplemented;
-
- return
- (NGetTrapAddress( theTrap, tType ) !=
- NGetTrapAddress( _Unimplemented, ToolTrap ));
- }
-
- /*-------------------------------------------------------------------------------------*/
-
- CIconHandle GetCICN(
- short id,
- Boolean using32BitQD )
- {
- CIconHandle cicn, resource;
- long dataSize;
-
- if (using32BitQD)
- cicn = (CIconHandle)GetCIcon( id );
- else
- {
- cicn = nil;
- resource = (CIconHandle)GetResource( 'cicn', id );
- if (resource != nil)
- {
- dataSize =
- (**resource).iconBMap.rowBytes * 2L *
- ((**resource).iconBMap.bounds.bottom - (**resource).iconBMap.bounds.top);
-
- cicn = (CIconHandle)NewHandleClear( (long)(sizeof( CIcon ) + dataSize) );
- if (cicn != nil)
- {
- (**cicn).iconPMap = (**resource).iconPMap;
- (**cicn).iconMask = (**resource).iconMask;
- (**cicn).iconBMap = (**resource).iconBMap;
-
- BlockMoveData(
- &(**resource).iconMaskData[0],
- &(**cicn).iconMaskData[0],
- dataSize );
- }
- }
- }
-
- return cicn;
- }
-
- /*-------------------------------------------------------------------------------------*/
-
- void PlotCICN(
- Rect *rect,
- CIconHandle cicn,
- Boolean using32BitQD )
- {
- GrafPtr savedPort;
- long dataSize;
-
- if (cicn == nil)
- return;
-
- if (using32BitQD)
- PlotCIcon( rect, cicn );
- else
- {
- GetPort( &savedPort );
- HLock( (Handle)cicn );
-
- /* Draw the icon image without any modifications. */
- (**cicn).iconMask.baseAddr = (Ptr)&(**cicn).iconMaskData[0];
-
- dataSize =
- (**cicn).iconBMap.rowBytes *
- ((**cicn).iconBMap.bounds.bottom - (**cicn).iconBMap.bounds.top);
-
- (**cicn).iconBMap.baseAddr = NewPtrClear( dataSize );
- if ((**cicn).iconBMap.baseAddr != nil)
- {
- BlockMoveData(
- &(**cicn).iconMaskData[dataSize / 2],
- (**cicn).iconBMap.baseAddr,
- dataSize );
-
- CopyMask(
- &(**cicn).iconBMap, &(**cicn).iconMask, &(savedPort->portBits),
- &(**cicn).iconBMap.bounds, &(**cicn).iconMask.bounds, rect );
-
- DisposePtr( (**cicn).iconBMap.baseAddr );
- }
-
- (**cicn).iconBMap.baseAddr = nil;
- HUnlock( (Handle)cicn );
- }
- }
-
- /*-------------------------------------------------------------------------------------*/
- // $$$$$ This routine has not been tested after adding the NewDeviceLoopDrawingProc for
- // PowerPC support.
-
- static void DeviceLoopPlus(
- Boolean usingSystem7,
- Boolean using32BitQD,
- RgnHandle drawingRgn,
- DeviceLoopDrawingProcPtr drawingProc,
- long userData,
- DeviceLoopFlags flags )
- {
- Rect screenRect;
- GDHandle device;
- RgnHandle screenRgn;
- RgnHandle savedClip;
- DeviceLoopDrawingUPP aDeviceLoopDrawingUPP;
-
- if (drawingProc == nil)
- return;
-
- if (usingSystem7)
- {
- aDeviceLoopDrawingUPP = NewDeviceLoopDrawingProc( drawingProc );
- DeviceLoop( drawingRgn, aDeviceLoopDrawingUPP, userData, flags );
- DisposeRoutineDescriptor( aDeviceLoopDrawingUPP );
- return;
- }
-
- if (using32BitQD)
- {
- (drawingProc)( 1, 0, nil, userData );
- return;
- }
-
- savedClip = NewRgn();
- GetClip( savedClip );
-
- screenRgn = NewRgn();
- device = GetDeviceList();
-
- while (device != nil)
- {
- screenRect = (**device).gdRect;
- GlobalToLocal( &topLeft( screenRect ) );
- GlobalToLocal( &botRight( screenRect ) );
-
- RectRgn( screenRgn, &screenRect );
- SectRgn( screenRgn, drawingRgn, screenRgn );
- SectRgn( screenRgn, savedClip, screenRgn );
-
- if (!EmptyRgn( screenRgn ))
- {
- SetClip( screenRgn );
- (*drawingProc)( (**(**device).gdPMap).pixelSize, (**device).gdFlags, device, userData );
- }
-
- device = GetNextDevice( device );
- }
-
- SetClip( savedClip );
- DisposeRgn( savedClip );
- DisposeRgn( screenRgn );
- }
-
- //---------------------------------------------------------------------------
- // get the current font state into theFontState
- void GetFontState(
- FontState *theFontState )
- {
- GrafPtr aPort;
-
- GetPort( &aPort );
- theFontState->txFont = aPort->txFont;
- theFontState->txFace = aPort->txFace;
- theFontState->txMode = aPort->txMode;
- theFontState->txSize = aPort->txSize;
- }
-
- //---------------------------------------------------------------------------
- // set the current font state using theFontState
- void SetFontState(
- FontState *theFontState )
- {
- GrafPtr aPort;
-
- GetPort( &aPort );
- aPort->txFont = theFontState->txFont;
- aPort->txFace = theFontState->txFace;
- aPort->txMode = theFontState->txMode;
- aPort->txSize = theFontState->txSize;
- }
-
- //---------------------------------------------------------------------------
- // convert theRect from local coordinates to global coordinates.
- void RectLocalToGlobal(
- Rect *theRect )
- {
- LocalToGlobal( &topLeft(*theRect) );
- LocalToGlobal( &botRight(*theRect) );
- }
-
- //---------------------------------------------------------------------------
- // convert theRect from global coordinates to local coordinates.
- void RectGlobalToLocal(
- Rect *theRect )
- {
- GlobalToLocal( &topLeft(*theRect) );
- GlobalToLocal( &botRight(*theRect) );
- }
-
- //---------------------------------------------------------------------------
- // convert theRgn from local coordinates to global coordinates. This routine
- // used to offset the region's rgnBBox, but that won't hold through DiffRgn
- // and other Rgn calcs.
- void RgnLocalToGlobal(
- RgnHandle theRgn )
- {
- Point thePt;
-
- thePt.h = thePt.v = 0;
- LocalToGlobal( &thePt );
- OffsetRgn( theRgn, thePt.h, thePt.v );
- // LocalToGlobal(&topLeft((**theRgn).rgnBBox));
- // LocalToGlobal(&botRight((**theRgn).rgnBBox));
- }
-
- //---------------------------------------------------------------------------
- // convert theRgn from global coordinates to local coordinates. This routine
- // used to offset the region's rgnBBox, but that won't hold through DiffRgn
- // and other Rgn calcs.
- void RgnGlobalToLocal(
- RgnHandle theRgn )
- {
- Point thePt;
-
- thePt.h = thePt.v = 0;
- GlobalToLocal( &thePt );
- OffsetRgn( theRgn, thePt.h, thePt.v );
- // GlobalToLocal(&topLeft((**theRgn).rgnBBox));
- // GlobalToLocal(&botRight((**theRgn).rgnBBox));
- }
-
- //---------------------------------------------------------------------------
- // Given two rectangles in global coords, interpolate one into the other,
- // making a zooming rectangle image on the screen. The rectangles and the
- // screen image are not altered. The rectangles are global.
- void ZoomRect(
- Rect *smallRect,
- Rect *bigRect,
- Boolean zoomUp )
- {
- #define FIX_ONE 0x10000
- #define ZOOM_STEPS 16
-
- Rect rect1,
- rect2,
- rect3,
- rect4;
- short i;
- GrafPtr savePort;
- GrafPort newPort;
- Fixed fract, // reals are too slow
- factor;
-
- GetPort(&savePort);
- OpenPort(&newPort); // full screen
- SetClip( LMGetGrayRgn() ); // clip to the gray rgn
- PenPat( (ConstPatternParam)&qd.gray ); // ConstPatternParam from non-universal THINK C headers
- PenMode( notPatXor );
-
- if (zoomUp)
- {
- rect1 = *smallRect;
- factor = FixRatio( 6, 5 ); // make bigger each time
- fract = FixRatio( 541, 10000 ); // 5/6 ^16 = 0.540877
- }
- else
- {
- rect1 = *bigRect;
- factor = FixRatio( 5, 6 ); // make smaller each time
- fract = FIX_ONE; // start full size
- }
-
- rect2 = rect1;
- rect3 = rect1;
- FrameRect( &rect1 ); // draw initial image
-
- for (i=1; i<=ZOOM_STEPS; i++)
- {
- rect4.left =
- FixRound( FixMul( fract,
- FIX_ONE * (*bigRect).left)
- + FixMul( FIX_ONE - fract, FIX_ONE * (*smallRect).left ) );
- rect4.right =
- FixRound( FixMul( fract,
- FIX_ONE * (*bigRect).right)
- + FixMul( FIX_ONE - fract, FIX_ONE * (*smallRect).right ) );
- rect4.top =
- FixRound( FixMul( fract,
- FIX_ONE * (*bigRect).top)
- + FixMul( FIX_ONE - fract, FIX_ONE * (*smallRect).top ) );
- rect4.bottom =
- FixRound( FixMul( fract,
- FIX_ONE * (*bigRect).bottom)
- + FixMul( FIX_ONE - fract, FIX_ONE * (*smallRect).bottom ) );
-
- FrameRect( &rect4 ); // draw newest
- FrameRect( &rect1 ); // erase oldest
- rect1 = rect2;
- rect2 = rect3;
- rect3 = rect4;
-
- // bump interpolation fraction
- fract = FixMul( fract, factor );
- }
- FrameRect( &rect1 ); // erase final image
- FrameRect( &rect2 );
- FrameRect( &rect3 );
-
- ClosePort( &newPort ); // disposes the clipping rgn
- SetPort( savePort );
- }
-
- #if 0
- //---------------------------------------------------------------------------
- pascal Handle newhandleclear(
- long lSize )
- {
- Handle theHandle;
-
- theHandle = NewHandle( lSize );
- if (theHandle != nil)
- {
- HLock( theHandle );
- blockErase( *theHandle, lSize );
- HUnlock( theHandle );
- }
-
- return theHandle;
- }
-
- //---------------------------------------------------------------------------
- pascal Ptr newptrclear(
- long lSize )
- {
- Ptr thePtr;
-
- thePtr = NewPtr( lSize );
- if (thePtr != nil)
- blockErase( thePtr, lSize );
-
- return thePtr;
- }
- #endif
-
- //---------------------------------------------------------------------------
- Boolean bAlmostEqual(
- Point pt1,
- Point pt2,
- short tolerance )
- {
- return ((abs( pt1.h - pt2.h ) < tolerance) && (abs( pt1.v - pt2.v ) < tolerance));
- }
-
- //---------------------------------------------------------------------------
- void ImAlive( void )
- {
- // *((Ptr) 0x824) ^= 0x80;
- }
-
- //---------------------------------------------------------------------------
- void Wait(
- long numTicks )
- {
- long finalTicks;
-
- Delay( numTicks,&finalTicks );
- }
-
- //---------------------------------------------------------------------------
- ulong lRandom( void )
- {
- return ((((unsigned long)Random())<<16) | ((unsigned long)Random()));
- }
-
- //---------------------------------------------------------------------------
- OSType lGetApplCreator( void )
- {
- FileParam myPB;
- Str31 s0;
- OSErr theErr;
-
- theErr = noErr;
-
- (*((FCBPBRec *)(&myPB))).ioFCBIndx = 0; // use ioRefNum
- (*((FCBPBRec *)(&myPB))).ioRefNum = CurResFile(); // our application
- (*((FCBPBRec *)(&myPB))).ioVRefNum = 0;
- (*((FCBPBRec *)(&myPB))).ioNamePtr = s0; // space for our name
- theErr = PBGetFCBInfo( (FCBPBPtr)&myPB, false );
-
- if (theErr == noErr)
- {
- myPB.ioFDirIndex = 0L; // use file name & VRefNum
- myPB.ioFVersNum = 0;
- theErr = PBGetFInfo( (ParmBlkPtr)&myPB, false );
- }
-
- if (theErr != noErr)
- myPB.ioFlFndrInfo.fdCreator = (OSType)0;
-
- return myPB.ioFlFndrInfo.fdCreator;
- }
-
- /*--------------------------------------------------------------------------*/
- ulong ulGetApplDate( void )
- {
- FileParam myPB;
- Str63 s0;
- OSErr theErr;
-
- (*((FCBPBRec*)(&myPB))).ioFCBIndx = 0; /* use ioRefNum */
- (*((FCBPBRec*)(&myPB))).ioRefNum = CurResFile(); /* our application */
- (*((FCBPBRec*)(&myPB))).ioVRefNum = 0;
- (*((FCBPBRec*)(&myPB))).ioNamePtr = s0;
- theErr = PBGetFCBInfo( (FCBPBPtr)&myPB, false );
-
- if (theErr == noErr)
- {
- myPB.ioFDirIndex = 0L; /* use file name & VRefNum */
- myPB.ioFVersNum = 0;
- theErr = PBGetFInfo( (ParmBlkPtr)&myPB, false );
- }
-
- if (theErr != noErr)
- myPB.ioFlCrDat = 0L;
-
- return myPB.ioFlCrDat;
- }
-
- //---------------------------------------------------------------------------
- Boolean bValidSystem( void )
- {
- SysEnvRec theWorld;
-
- if (SysEnvirons( curSysEnvVers, &theWorld ) == envNotPresent)
- return false;
-
- return true;
- }
-
- //---------------------------------------------------------------------------
- ulong ulTime(void)
- {
- ulong ulTempTime;
-
- GetDateTime( &ulTempTime );
- return ulTempTime;
- }
-
- //---------------------------------------------------------------------------
- void spinCursor( void )
- {
- if (iGetCursor() != (256+iWhichCursor))
- bSetCursor( 256+iWhichCursor );
- if (TickCount() - lCursorTicks >= 15L)
- { // spin it every 15 ticks
- iWhichCursor = (iWhichCursor+1) % 8;
- bSetCursor( 256+iWhichCursor );
- lCursorTicks = TickCount();
- }
- }
-
- //---------------------------------------------------------------------------
- short iToolVersion(
- Str255 sVersion )
- {
- if (sVersion != nil)
- GetIndString( sVersion, CStringsID, 17 ); // C Tools
-
- return 1;
- }
-
- //---------------------------------------------------------------------------
- void drawSICN(
- Ptr pSICN,
- short iIndex,
- Rect *rDst )
- {
- bmSrc.baseAddr = pSICN + (iIndex << 5);
- CopyBits( &bmSrc, &qd.thePort->portBits, &rTemp, rDst, srcCopy, nil );
- }
-
-
- //---------------------------------------------------------------------------
- MenuHandle mhSetMenuItem(
- Boolean bEnable,
- MenuHandle theMenu,
- short theItem )
- {
- if (theMenu != nil)
- {
- if (bEnable)
- EnableItem( theMenu, theItem );
- else
- DisableItem( theMenu, theItem );
- }
-
- return theMenu;
- }
-
- //---------------------------------------------------------------------------
- Rect *rCenterRectOnPoint(Point pCenter,Rect *rDst)
- {
- Point pSize;
-
- pSize.h = rDst->right-rDst->left; pSize.v = rDst->bottom-rDst->top;
-
- rDst->right = pSize.h + (rDst->left = pCenter.h-(rDst->right-rDst->left>>1));
- rDst->bottom = pSize.v + (rDst->top = pCenter.v-(rDst->bottom-rDst->top>>1));
-
- return rDst;
- }
-
- #if 0
- //---------------------------------------------------------------------------
- // centers rDst in rSrc
- Rect *rCenterRectInRect(
- Rect *rSrc,
- Rect *rDst )
- {
- Point pCenter;
- Rect *theRect;
-
- pCenter.h = rSrc->right + (rSrc->left >> 1);
- pCenter.v = rSrc->top + ((rSrc->bottom - rSrc->top) * 3 / 7);
- theRect = rCenterRectOnPoint( pCenter, rDst );
- if ((theRect->top-6) < rSrc->top)
- {
- // don't let the top go past the rSrc->top
- theRect->bottom += (rSrc->top - (theRect->top-6));
- theRect->top += (rSrc->top - (theRect->top-6));
- }
- return theRect;
- }
- #endif
-
- //---------------------------------------------------------------------------
- // "centers" rDst in rSrc
- Rect *rCenterRectInRect(
- Rect *rSrc,
- Rect *rDst )
- {
- short iDstHeight,
- iDstWidth,
- iSrcHeight,
- iSrcWidth;
-
- // if the rect is empty, don't do anything.
- if (EmptyRect( rSrc ))
- return nil;
-
- iDstHeight = rDst->bottom - rDst->top;
- iDstWidth = rDst->right - rDst->left;
- iSrcHeight = rSrc->bottom - rSrc->top;
- iSrcWidth = rSrc->right - rSrc->left;
-
- rDst->top = rSrc->top + (iSrcHeight - iDstHeight) * 3 / 7;
- // if (rDst->top < 0) // don't let it go above zero
- // rDst->top = 0;
- rDst->bottom = rDst->top + iDstHeight;
- rDst->left = rSrc->left + (iSrcWidth - iDstWidth) / 2;
- // if (rDst->left < 0) // don't let it go to the left of zero
- // rDst->left = 0;
- rDst->right = rDst->left + iDstWidth;
-
- return rDst;
- }
-
-
- //---------------------------------------------------------------------------
- Boolean bSetCursor(
- short iCursorID )
- {
- CursHandle theCursor;
-
- if (iCursorID == 0)
- SetCursor( &qd.arrow );
- else
- {
- theCursor = GetCursor( iCursorID );
- if (theCursor != nil)
- SetCursor( *theCursor );
- else
- return false;
- }
- iCurCursorID = iCursorID;
-
- return true;
- }
-
- //---------------------------------------------------------------------------
- Boolean bSetCursorWatch( void )
- {
- return bSetCursor( watchCursor );
- }
-
- //---------------------------------------------------------------------------
- short iGetCursor(void)
- {
- return iCurCursorID;
- }
-
- //---------------------------------------------------------------------------
- Handle next1Resource(
- ResType theResType,
- Handle theHandle )
- {
- short iResources, iIndex;
-
- iResources = Count1Resources( theResType );
-
- SetResLoad( false );
- for (iIndex=1; iIndex != iResources+1; iIndex++)
- {
- if (theHandle == (Handle) Get1IndResource(theResType,iIndex))
- {
- SetResLoad(true);
- return
- (Handle)Get1IndResource(
- theResType, (iIndex == iResources) ? 1 : ++iIndex );
- }
- }
- SetResLoad( true );
-
- return 0;
- }
-
- //---------------------------------------------------------------------------
- short iEventModifiers( void )
- {
- EventRecord theEvent;
-
- (void)EventAvail( nullEvent, &theEvent );
-
- return (theEvent.modifiers);
- }
-
- //---------------------------------------------------------------------------
- void blockErase(
- register Ptr pBuffer,
- long lSize )
- {
- register Ptr pBufferEnd;
-
- #if 0
- // single bytes
- pBufferEnd = pBuffer + lSize;
- while (pBuffer < pBufferEnd)
- *pBuffer++ = 0;
- #else
- // faster blockErase
- if (!lSize)
- return;
-
- pBufferEnd = pBuffer + lSize - 1;
-
- // if it starts on an odd boundary, clear the first byte.
- if ((long)pBuffer & 1)
- *pBuffer++ = 0;
-
- // clear 2 bytes at a time.
- while (pBuffer < pBufferEnd)
- {
- *((short *)pBuffer) = 0;
- pBuffer += 2;
- }
-
- if (pBuffer == pBufferEnd)
- *pBuffer = 0;
- #endif
- }
-
- //---------------------------------------------------------------------------
- void blockRandomize(
- register Ptr pBuffer,
- long lSize )
- {
- Ptr pBufferEnd;
-
- if (lSize <= 0L)
- return;
-
- pBufferEnd = pBuffer + lSize - 1;
-
- // if it starts on an odd boundary, randomize the first byte.
- if ((long)pBuffer & 1)
- *pBuffer++ = Random();
-
- // randomize 2 bytes at a time.
- while (pBuffer < pBufferEnd)
- {
- *((short*)pBuffer) = Random();
- pBuffer += 2;
- }
-
- // if there is one byte left to do, do it.
- if (pBuffer == pBufferEnd)
- *pBuffer = Random();
- }
-
- //----------------------------------------------------------------------
- // GetMainScreenRect - returns the rect of the main screen from the GDevice list.
-
- void GetMainScreenRect(
- Rect *theMainScreenRect )
- {
- if (HaveCQD())
- {
- GDHandle theGDHand = LMGetMainDevice();
- *theMainScreenRect = (**theGDHand).gdRect;
- }
- else
- *theMainScreenRect = LMGetWMgrPort()->portRect;
-
- theMainScreenRect->top += GetMBarHeight();
- }
-
- Boolean EqualPicts(
- PicHandle pictA,
- PicHandle pictB )
- {
- long size, offset, sofar;
- Ptr ptrA, ptrB;
-
- if (pictA == pictB)
- return true;
-
- if (((**pictA).picSize) != ((**pictB).picSize))
- return false;
-
- offset = 10;
- size = GetHandleSize( (Handle)pictA );
-
- ptrA = (Ptr)(*pictA) + 10;
- ptrB = (Ptr)(*pictB) + 10;
-
- while (*ptrA == *ptrB)
- {
- sofar = (long)ptrA - (long)*pictA;
-
- if (((long)ptrA - (long)*pictA) >= size - 4)
- return true;
-
- ++ptrA; ++ptrB;
- ++offset;
- }
-
- if (offset > 10)
- ++offset;
-
- return false;
- }
-
-
- void GetOrigin(
- Point *origin )
- {
- origin->h = qd.thePort->portRect.left;
- origin->v = qd.thePort->portRect.top;
- }
-
- void CopyFile (FSSpec* src, FSSpec* dest)
- {
-
- short srcRef;
- short destRef;
- const short kBufferSize = 1000 ;
- char buffer[kBufferSize] ;
- long bytesLeft;
- long count ;
- FInfo ignore;
- FInfo srcInfo;
-
- FSpGetFInfo( src, &srcInfo );
-
-
- if (FSpGetFInfo(dest, &ignore ) != noErr)
- {
- FSpCreate (dest, srcInfo.fdCreator, srcInfo.fdType, 0);
- }
-
- srcRef = HOpen (src->vRefNum, src->parID, src->name, fsRdPerm, &srcRef);
- destRef = HOpen (src->vRefNum, src->parID, src->name, fsRdWrPerm, &destRef);
-
- GetEOF (srcRef, &bytesLeft);
-
- while( bytesLeft > 0 )
- {
- count = bytesLeft < kBufferSize? bytesLeft: kBufferSize ;
- FSRead (srcRef, &count, buffer);
- FSWrite (destRef, &count, buffer);
- bytesLeft -= count ;
- }
-
- FSClose (srcRef); FSClose (destRef);
-
-
- srcRef = HOpenRF (src->vRefNum, src->parID, src->name, fsRdPerm, &srcRef);
- destRef = HOpenRF (src->vRefNum, src->parID, src->name, fsRdWrPerm, &destRef);
-
- GetEOF (srcRef, &bytesLeft);
-
- while( bytesLeft > 0 )
- {
- count = bytesLeft < kBufferSize? bytesLeft: kBufferSize ;
- FSRead (srcRef, &count, buffer);
- FSWrite (destRef, &count, buffer);
- bytesLeft -= count ;
- }
-
- FSClose (srcRef); FSClose (destRef);
-
-
- }
-
-
-
- void MakeDatedUniqueFSSpec (FSSpec* fsSpec)
- {
- unsigned long secs;
- static short index = 1;
- Str32 indexString;
- Str32 tmpName;
- Str32 tmpString;
- Str32 dateString;
- FSSpec tmpSpec;
- FInfo ignore ;
-
- GetDateTime(&secs);
-
- IUDateString(secs,shortDate,(StringPtr)dateString);
- sCopyStr (fsSpec->name, tmpName);
- sAppendStr ("\p ", tmpName);
- sAppendStr (dateString, tmpName);
- sAppendStr ("\p ", tmpName);
-
- do
- {
-
- sCopyStr (tmpName, tmpString);
- NumToString (index, (StringPtr) indexString);
- sAppendStr (indexString, tmpString);
- sCopyStr (tmpString, fsSpec->name);
- ++index;
-
- } while (FSpGetFInfo( fsSpec, &ignore ) == noErr);
-
- }
-
-
-
-